package PowerWord.UI.Exercise;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;

public class M2MAnswerViewer extends View {

	private final Paint mPaint = new Paint();
	protected int numItems = 1;
	protected int[] answers = null;
	int base;
	int step;
	
	public M2MAnswerViewer(Context context) {
		super(context);
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		setLayoutParams(params);
		mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.RED);
        mPaint.setAlpha(0xFF);
	}
	
	public void SetAnswer(int s, int[] a){
		answers = a;
		numItems = s;
	}
	
	private int GetHeight(int pos){
		return base + pos * step;
	}

	@Override
	protected void onDraw(Canvas canvas){
		step = getHeight() / numItems;
		base = step / 2;
		int width = getWidth();
		for(int i=0; i<numItems; ++i){
			canvas.drawLine(0, GetHeight(answers[i]), width, GetHeight(i), mPaint);
		}
	}
}
